// app.js
import $http from './utils/request.js'
import { token } from './api/auth.js'
import Storage from './utils/storage.js'

App({
  $http,
  onLaunch() {
    // 展示本地存储能力
    const logs = Storage.getLogs() || []
    logs.unshift(Date.now())
    Storage.setLogs(logs)

    // 登录
    wx.login({
      success: async res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        let loginRes = await token(res.code);
        if(loginRes && loginRes.code === 200){
          Storage.setToken(loginRes.data.tokenName, loginRes.data.tokenValue)
        }
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
